//
//  GameViewModel.swift
//  DouYuZB
//
//  Created by James on 2017/10/25.
//  Copyright © 2017年 James. All rights reserved.
//

import UIKit

class GameViewModel {
    lazy var dataModels:[GameModel] = [GameModel]()
}

extension GameViewModel{
    func loadAllGameData(finishedCallBack:@escaping ()->()) -> () {
        NetWorkManger.requestData(type: .GET, urlString: "http://capi.douyucdn.cn/api/v1/getColumnDetail", parameters: ["shortName":"game"]) {[weak self] (result) in
            guard let resultDict = result as? [String:Any] ,
                let dataArray = resultDict["data"] as? [[String:Any]] else{
                    return
            }
            
            //字典转模型
            for dict in dataArray {
                self?.dataModels.append(GameModel(dict: dict))
            }
            
            finishedCallBack()
        }
    }
}
